 package server;

 import java.util.concurrent.ScheduledFuture;
 import java.util.concurrent.ScheduledThreadPoolExecutor;
 import java.util.concurrent.ThreadFactory;
 import java.util.concurrent.TimeUnit;
 import java.util.concurrent.atomic.AtomicInteger;
 import org.apache.logging.log4j.LogManager;
 import org.apache.logging.log4j.Logger;
 import tools.Randomizer;


 public abstract class Timer
 {
/*  15 */   private static final AtomicInteger threadNumber = new AtomicInteger(1);
   protected String name;
   private ScheduledThreadPoolExecutor ses;

   public void start() {
/*  20 */     if (this.ses != null && !this.ses.isShutdown() && !this.ses.isTerminated()) {
       return;
     }
/*  23 */     this.ses = new ScheduledThreadPoolExecutor(5, new RejectedThreadFactory());
/*  24 */     this.ses.setKeepAliveTime(10L, TimeUnit.MINUTES);
/*  25 */     this.ses.allowCoreThreadTimeOut(true);
/*  26 */     this.ses.setMaximumPoolSize(20);
/*  27 */     this.ses.setContinueExistingPeriodicTasksAfterShutdownPolicy(false);
   }


   public ScheduledThreadPoolExecutor getSES() {
/*  32 */     return this.ses;
   }

   public void stop() {
/*  36 */     if (this.ses != null) {
/*  37 */       this.ses.shutdown();
     }
   }




   public ScheduledFuture<?> register(Runnable command, long period, long initialDelay) {
/*  45 */     if (this.ses == null) {
/*  46 */       return null;
     }
















/*  64 */     return this.ses.scheduleAtFixedRate(new LoggingSaveRunnable(command), initialDelay, period, TimeUnit.MILLISECONDS);
   }




   public ScheduledFuture<?> register(Runnable command, long period) {
/*  71 */     if (this.ses == null) {
/*  72 */       return null;
     }
/*  74 */     return this.ses.scheduleAtFixedRate(new LoggingSaveRunnable(command), 0L, period, TimeUnit.MILLISECONDS);
   }




   public ScheduledFuture<?> schedule(Runnable command, long delay) {
/*  81 */     if (this.ses == null) {
/*  82 */       return null;
     }












/*  96 */     return this.ses.schedule(new LoggingSaveRunnable(command), delay, TimeUnit.MILLISECONDS);
   }

   public ScheduledFuture<?> scheduleAtTimestamp(Runnable command, long timestamp) {
/* 100 */     return schedule(command, timestamp - System.currentTimeMillis());
   }

   public static class WorldTimer
     extends Timer {
/* 105 */     private static final WorldTimer instance = new WorldTimer();





     public static WorldTimer getInstance() {
/* 112 */       return instance;
     }
   }

   public static class MapTimer
     extends Timer {
/* 118 */     private static final MapTimer instance = new MapTimer();





     public static MapTimer getInstance() {
/* 125 */       return instance;
     }
   }

   public static class BuffTimer
     extends Timer {
/* 131 */     private static final BuffTimer instance = new BuffTimer();





     public static BuffTimer getInstance() {
/* 138 */       return instance;
     }
   }

   public static class EventTimer
     extends Timer {
/* 144 */     private static final EventTimer instance = new EventTimer();





     public static EventTimer getInstance() {
/* 151 */       return instance;
     }
   }

   public static class CloneTimer
     extends Timer {
/* 157 */     private static final CloneTimer instance = new CloneTimer();





     public static CloneTimer getInstance() {
/* 164 */       return instance;
     }
   }

   public static class EtcTimer
     extends Timer {
/* 170 */     private static final EtcTimer instance = new EtcTimer();





     public static EtcTimer getInstance() {
/* 177 */       return instance;
     }
   }

   public static class CheatTimer
     extends Timer {
/* 183 */     private static final CheatTimer instance = new CheatTimer();





     public static CheatTimer getInstance() {
/* 190 */       return instance;
     }
   }

   public static class PingTimer
     extends Timer {
/* 196 */     private static final PingTimer instance = new PingTimer();





     public static PingTimer getInstance() {
/* 203 */       return instance;
     }
   }

   public static class GuiTimer
     extends Timer {
/* 209 */     private static final GuiTimer instance = new GuiTimer();





     public static GuiTimer getInstance() {
/* 216 */       return instance;
     }
   }

   public static class PlayerTimer
     extends Timer {
/* 222 */     private static final PlayerTimer instance = new PlayerTimer();





     public static PlayerTimer getInstance() {
/* 229 */       return instance;
     }
   }

   private static class LoggingSaveRunnable
     implements Runnable {
/* 235 */     private static final Logger logger = LogManager.getLogger(LoggingSaveRunnable.class.getName());
     final Runnable command;

     public LoggingSaveRunnable(Runnable r) {
/* 239 */       this.command = r;
     }


     public void run() {
       try {
/* 245 */         this.command.run();
/* 246 */       } catch (Throwable t) {
/* 247 */         logger.error("LoggingSaveRunnable_run异常", t);
       }
     }
   }

   private class RejectedThreadFactory
     implements ThreadFactory {
/* 254 */     private final AtomicInteger threadNumber2 = new AtomicInteger(1);
     private final String tname;

     public RejectedThreadFactory() {
/* 258 */       this.tname = Timer.this.name + Randomizer.nextInt();
     }


     public Thread newThread(Runnable r) {
/* 263 */       Thread t = new Thread(r);
/* 264 */       t.setName(this.tname + "-W-" + Timer.threadNumber.getAndIncrement() + "-" + this.threadNumber2.getAndIncrement());
/* 265 */       return t;
     }
   }
 }


/* Location:              C:\PGX\Server.jar!\server\Timer.class
 * Java compiler version: 8 (52.0)
 * JD-Core Version:       1.1.3
 */